// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'

import router from './router/index.js'

import store from './store/store.js'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import './styles/index.scss';

Vue.config.productionTip = false;

//路由守卫的功能就是决定页面是否继续跳转
router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('mytoken');
  if(token){
    next();
  }else{
    if(to.path=='/login'){
      next();
    }else{
      next({path:'/login'})
    }
  }
})

// router.beforeEach((to, from, next) => {
//   let token = localStorage.getItem('mytoken');
//   if(token){
//     next();
//   }else{
//     if(to.path == '/login'){
//       next();
//     }else{
//       next({path: '/login'})
//     }
//   }
// })

Vue.use(ElementUI);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
